import QtQuick
import QtQuick.Controls

Rectangle {
    id: root
    
    property var minionData
    property bool isHand: false
    property bool isOnBoard: false
    property bool isInShop: false
    property bool isOpponent: false
    
    signal clicked()
    
    width: 100
    height: 140
    color: getKingdomColor(minionData.kingdom)
    radius: 8
    border.color: getBorderColor()
    border.width: 2
    
    // 金色边框表示三连
    Rectangle {
        anchors.fill: parent
        color: "transparent"
        radius: parent.radius
        border.color: minionData.isGolden ? "#FFD700" : "transparent"
        border.width: 3
        visible: minionData.isGolden
    }
    
    // 嘲讽标识
    Text {
        anchors.top: parent.top
        anchors.right: parent.right
        text: "💢"
        visible: minionData.hasTaunt
        font.pixelSize: 12
    }
    
    Column {
        anchors.centerIn: parent
        spacing: 5
        width: parent.width - 10
        
        // 随从名称
        Text {
            text: minionData.name
            color: "white"
            font.pixelSize: minionData.isGolden ? 14 : 12
            font.bold: true
            width: parent.width
            wrapMode: Text.Wrap
            horizontalAlignment: Text.AlignHCenter
        }
        
        // 等级
        Text {
            text: "★".repeat(minionData.tier)
            color: "#FFD700"
            font.pixelSize: 12
            anchors.horizontalCenter: parent.horizontalCenter
        }
        
        // 攻击力和生命值
        Row {
            spacing: 8
            anchors.horizontalCenter: parent.horizontalCenter
            
            Text {
                text: "⚔️" + minionData.attack
                color: "#FF6B6B"
                font.pixelSize: 14
                font.bold: true
            }
            
            Text {
                text: "❤️" + minionData.health
                color: "#4CAF50" 
                font.pixelSize: 14
                font.bold: true
            }
        }
        
        // 势力
        Text {
            text: getKingdomText(minionData.kingdom)
            color: "white"
            font.pixelSize: 10
            anchors.horizontalCenter: parent.horizontalCenter
        }
        
        // 技能提示
        Text {
            text: minionData.skills && minionData.skills.length > 0 ? "有技能" : ""
            color: "#FFD700"
            font.pixelSize: 9
            anchors.horizontalCenter: parent.horizontalCenter
            visible: !isOpponent
        }
        
        // 商店价格
        Text {
            text: isInShop ? minionData.cost + "💰" : ""
            color: "#FFD700"
            font.pixelSize: 12
            font.bold: true
            anchors.horizontalCenter: parent.horizontalCenter
            visible: isInShop
        }
    }
    
    // 点击区域
    MouseArea {
        anchors.fill: parent
        enabled: !isOpponent
        onClicked: root.clicked()
        
        hoverEnabled: true
        onEntered: {
            if (!isOpponent) {
                parent.scale = 1.05
                parent.z = 1
            }
        }
        onExited: {
            parent.scale = 1.0
            parent.z = 0
        }
    }
    
    // 获取边框颜色
    function getBorderColor() {
        if (isOpponent) return "#FF0000"
        if (isInShop) return "#FFD700"
        if (isOnBoard) return "#00FF00" 
        if (isHand) return "#1E90FF"
        return "#666666"
    }
    
    // 势力颜色映射
    function getKingdomColor(kingdom) {
        switch(kingdom) {
            case "wei": return "#2F4F4F";
            case "shu": return "#8B0000";
            case "wu": return "#006400";
            case "qun": return "#4B0082";
            default: return "#2d3047";
        }
    }
    
    function getKingdomText(kingdom) {
        switch(kingdom) {
            case "wei": return "魏";
            case "shu": return "蜀";
            case "wu": return "吴"; 
            case "qun": return "群";
            default: return "未知";
        }
    }
}